package logic

import (
	"cart_srv/models/redis"
	"context"
	"errors"

	"cart_srv/cart_srv"
	"cart_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateCartCheckedLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateCartCheckedLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateCartCheckedLogic {
	return &UpdateCartCheckedLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateCartCheckedLogic) UpdateCartChecked(in *cart_srv.UpdateCartCheckedRequest) (*cart_srv.UpdateCartCheckedResponse, error) {
	// todo: add your logic here and delete this line
	if redis.CartIsNilOrNotNil(int(in.UserId)) {
		return nil, errors.New("购物车为空")
	}
	err := redis.UpdateCartChecked(int(in.UserId), int(in.ShopId))
	if err != nil {
		return nil, err
	}
	return &cart_srv.UpdateCartCheckedResponse{}, nil
}
